<?php

/**
 * 管理用户模型
 * 
  + -----------------------------------------------------
 * Date 2013-3-8
  + -----------------------------------------------------
 */
class AreaModel extends Model {

    protected $_map = array(
        'id'       => 'area_id',
        'parentid' => 'parent_id',
    );
    protected $_validate = array(
        array('parent_id', 'check_type', '无法添加子地区了', 1, 'callback', 3),
    );
    protected $_auto = array(
        array('type', 'getType', 3, 'callback'),
    );

    function check_type($parent_id) {
        $parent = $this->find($parent_id);
        if ($parent['type'] > 2) {
            return false;
        } else {
            return true;
        }
    }

    function getType() {
        $parent_id = format_int($_POST['parent_id']);
        if ($parent_id == 0) {
            return 1;
        }
        $parent = $this->find($parent_id);
        if (!$parent) {
            return 1;
        }
        $type = $parent['type'] + 1;
        return $type;
    }

}

?>